package LimitedTimeGame.Day_0305;

/**
 * @author zxc
 * @date 2023/03/05 10:03
 **/

import java.util.ArrayList;
import java.util.List;

/**
 * 题目 ：经营摩天轮的最大利润
 *
 * 提示：
 * n == customers.length
 * 1 <= n <= 105
 * 0 <= customers[i] <= 50
 * 1 <= boardingCost, runningCost <= 100
 *
 */
public class MinOperationsMaxProfit {
    public static void main(String[] args) {
        System.out.println(minOperationsMaxProfit(new int[]{8,3} ,5 , 6));
    }
    /**
     * 思路 ：
     * ===》
     * 即，使用list集合，来保存前n次轮转总共利润;
     * （1）若是利润为正的话，则去判断是否大于最大利润 && 若是大于最大利润的话，则将当前轮转次数赋予给minNumber;
     * （2）while循环遍历，直至整个customers数组被遍历完 && 所有游客都上摩天轮;
     *
     * @param customers
     * @param boardingCost
     * @param runningCost
     * @return
     */
    public static int minOperationsMaxProfit(int[] customers, int boardingCost, int runningCost) {
        List<Integer> list = new ArrayList<>();
        int peopleNumber = 0;
        int len = customers.length;
        int k = 0;
        list.add(0);
        int minNumber = Integer.MAX_VALUE;
        int maxValue = 0;
        while(k < len || peopleNumber > 0){
            if(k < len){
                peopleNumber += customers[k];
            }
            if(peopleNumber > 4){
                peopleNumber -= 4;
                int value = 4 * boardingCost - runningCost + list.get(k);
                list.add(value);
                if(value > maxValue){
                    maxValue = value;
                    minNumber = k + 1;
                }
            }
            else {
                int value = peopleNumber * boardingCost - runningCost + list.get(k);
                peopleNumber = 0;
                list.add(value);
                if(value > maxValue){
                    maxValue = value;
                    minNumber = k + 1;
                }
            }
            k++;
        }
        return minNumber == Integer.MAX_VALUE ? -1 : minNumber;
    }
}
